package grafica.jugador.ventanas;

import grafica.jugador.controladores.ControladorLogin;

import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Toolkit;

import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JButton;

import persistencia.PersistenciaException;

public class Login {

	private JDialog jDialogLogin = null;  //  @jve:decl-index=0:visual-constraint="167,28"
	private JPanel jContentPaneLogin = null;
	private JPanel jPanelLogin = null;
	private JLabel jLabelLogin = null;
	private JTextField jTextFieldUsuario = null;
	private JButton jButtonCancelar = null;
	private JButton jButtonAceptar = null;
	private ControladorLogin controladorLogin;
	private JLabel jLabelInfo = null;

	
	
	public Login(){
		controladorLogin = new ControladorLogin(this);
	}
	/**
	 * This method initializes jDialogLogin	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getJDialogLogin() {
		if (jDialogLogin == null) {
			jDialogLogin = new JDialog();
			jDialogLogin.setSize(new java.awt.Dimension(330,206));
			jDialogLogin.setVisible(false);
			jDialogLogin.setTitle("Login");
			jDialogLogin.setContentPane(getJContentPaneLogin());
			jDialogLogin.setLocationRelativeTo(null);			
					
		}
		return jDialogLogin;
	}

	/**
	 * This method initializes jContentPaneLogin	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPaneLogin() {
		if (jContentPaneLogin == null) {
			jContentPaneLogin = new JPanel();
			jContentPaneLogin.setLayout(new BorderLayout());
			jContentPaneLogin.add(getJPanelLogin(), java.awt.BorderLayout.CENTER);
		}
		return jContentPaneLogin;
	}

	/**
	 * This method initializes jPanelLogin	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelLogin() {
		if (jPanelLogin == null) {
			jLabelInfo = new JLabel();
			jLabelInfo.setText("");
			jLabelInfo.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
			jLabelInfo.setPreferredSize(new java.awt.Dimension(315,35));
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setHgap(25);
			flowLayout.setVgap(30);
			jLabelLogin = new JLabel();
			jLabelLogin.setText("Usuario:");
			jLabelLogin.setPreferredSize(new java.awt.Dimension(55,20));
			jPanelLogin = new JPanel();
			jPanelLogin.setLayout(flowLayout);
			jPanelLogin.add(jLabelLogin, null);
			jPanelLogin.add(getJTextFieldUsuario(), null);
			jPanelLogin.add(getJButtonAceptar(), null);
			jPanelLogin.add(getJButtonCancelar(), null);
			jPanelLogin.add(jLabelInfo, null);
		}
		return jPanelLogin;
	}

	/**
	 * This method initializes jTextFieldUsuario	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldUsuario() {
		if (jTextFieldUsuario == null) {
			jTextFieldUsuario = new JTextField();
			jTextFieldUsuario.setPreferredSize(new java.awt.Dimension(150,20));
		}
		return jTextFieldUsuario;
	}

	/**
	 * This method initializes jButtonCancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancelar() {
		if (jButtonCancelar == null) {
			jButtonCancelar = new JButton();
			jButtonCancelar.setPreferredSize(new java.awt.Dimension(90,25));
			jButtonCancelar.setText("Cancelar");
			ActionListener BotonCancelar = new ActionListener(){
				public void actionPerformed (ActionEvent e){ 				
					jDialogLogin.dispose(); 
					System.exit(0); 
				}
			};
			jButtonCancelar.addActionListener(BotonCancelar );
		}
		return jButtonCancelar;
	}

	/**
	 * This method initializes jButtonAceptar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAceptar() {
		if (jButtonAceptar == null) {
			jButtonAceptar = new JButton();
			jButtonAceptar.setPreferredSize(new java.awt.Dimension(90,25));
			jButtonAceptar.setText("Aceptar");
			ActionListener BotonAceptar = new ActionListener(){
				public void actionPerformed (ActionEvent e){					
						controladorLogin.LoginJugador(jTextFieldUsuario.getText().toString());											
				}
			};
			jButtonAceptar.addActionListener(BotonAceptar);
			
		}
		return jButtonAceptar;
	}

	public void setVisible (boolean b)	{	
			getJDialogLogin().setVisible(b);
	}
	public void setJLabelInfo(String info){
		jLabelInfo.setText(info);
	}
	public void cerrarVentana(){
		jDialogLogin.dispose(); 		
//		System.exit(0);
	
	}
}
